#include "StdAfx.h"
#include "test.h"
#include <iostream>
using namespace std;

namespace Zen{namespace test{

	void print(const char *fmt, ...)
	{
		char s[80] = "";
		int paramCount = strlen(fmt);
		cout << "paramCount = " << paramCount;

		char *p = (char *)(&fmt) + sizeof(char *);
		int *pi = (int *)p;
		for (int i=0; i < paramCount; i++)
		{
			char line[80] = "";
			strcpy_s(line, 80, "param");
			itoa(i+1, s, 10);
			strcat(line, s);
			strcat(line, "=");
			switch(fmt[i])
			{
			case 'i':
			case 's':
				itoa((*pi),s,10);
				strcat(line, s);
				pi++;
				break;
			case 'c':
				{
					int len = strlen(line);
					line[len] = (char)(*pi);
					line[len+1] = '\0';
				}
				break;
			case 'l':
				ltoa((*(long *)pi),s,10);
				strcat(line, s);
				pi++;
				break;
			default:
				break;
			}

			cout << line<< endl;
		}
	}

	int Max(int n, ...)
	{
		int *p = &n + 1;
		int ret = *p;
		for (int i=0; i < n; i++)
		{
			if (ret < *(p + i))
				ret = *(p + i);
		}
		return ret;
	}

}}
